from datetime import datetime
from .base import BaseModel
from ..extensions.extensions import db

class RolePermission(BaseModel):
    """角色权限关系表"""
    __tablename__ = 'role_permissions'
    
    role_id = db.Column(db.Integer, nullable=False, comment='角色ID')
    permission_id = db.Column(db.Integer, nullable=False, comment='权限ID')
    
    def to_dict(self):
        """转换为字典"""
        return {
            'id': self.id,
            'role_id': self.role_id,
            'permission_id': self.permission_id,
            'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None,
            'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S') if self.updated_at else None
        } 